package com.qzf.test.test;

import com.qzf.test.model.Brand;
import com.qzf.test.model.Cell;
import com.qzf.test.model.Layer;

import java.util.Random;

public class TestBuilderLayer {

    public static Random random=new Random();

    //定义一个数组存储卡牌的名称
    public static String [] brandNames={"刷子","剪刀","叉子","手套","水桶","火","玉米","球","瓶子","白菜",
            "稻草","肉腿","胡萝卜","苹果","铃铛","青草"};

    public static String getBrandName(){
        int index =random.nextInt(brandNames.length);
        return brandNames[index];
    }

    public static void main(String[] args) {
        Layer layer=new Layer(6,6);
        Brand[] brands =new Brand[layer.getCapacity()];

        //循环遍历给卡牌数组赋值
        for (int i=0;i<brands.length;i+=3){
            String brandName=getBrandName();
            Brand b1=new Brand(brandName);
            Brand b2=new Brand(brandName);
            Brand b3=new Brand(brandName);
            brands[i]=b1;
            brands[i+1]=b2;
            brands[i+2]=b3;
        }

        //随机置换
        for (int i=0;i<brands.length;i++){
            Brand brandA=brands[i];
            int index=random.nextInt(brands.length);
            Brand brandB=brands[index];

            brands[i]=brandB;
            brands[index]=brandA;
        }

        for (int i=0;i<brands.length;i++){
            System.out.print(brands[i].getName()+" ");
        }

        System.out.println("================验证图层的数据===============");
        Cell[][] cells=layer.getCells();
        int flag =0;
        for (int row=0;row<cells.length;row++){
            for (int col=0;col<cells[row].length;col++){
                System.out.println(col+"\t"+row);
                Cell c=new Cell();
                c.setState(1);
                c.setBrand(brands[flag++]);
                cells[row][col]=c;
            }
        }

        for (int row=0;row<cells.length;row++){
            for(int col=0;col<cells[row].length;col++){
                Cell cell=cells[row][col];
                System.out.print(cell.getBrand().getName()+" ");
            }
            System.out.println("");
        }
    }




}
